package com.guigu.erp.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.erp.dto.ManufactureApplyDto;
import com.guigu.erp.mapper.ManufactureApplyMapper;
import com.guigu.erp.pojo.DesignModule;
import com.guigu.erp.pojo.ManufactureApply;
import com.guigu.erp.pojo.StorageCell;
import com.guigu.erp.service.ManufactureApplyService;
import com.guigu.erp.utils.PageUtils;
import com.guigu.erp.vo.DesignFileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lenovo
 */
@Service
public class ManufactureApplyServiceImpl extends ServiceImpl<ManufactureApplyMapper, ManufactureApply> implements ManufactureApplyService{
    @Autowired
    private ManufactureApplyService manufactureApplyService;

    @Autowired
    private ManufactureApplyMapper manufactureApplyMapper;

    /**
     * 获取Id最大的生产计划编号
     * @return
     */
    @Override
    public String getMaxApplyId() {
        ManufactureApply manufactureApply=manufactureApplyMapper.queryMaxApplyId();
        if (manufactureApply==null){
            return null;
        }
        // 获取库存配置单库存配置单编号
        String applyId=manufactureApply.getApplyId();
        return applyId;
    }

    @Override
    public PageUtils<ManufactureApply> recheckPage(DesignFileVo vo, int pageNo, int pageSize) {
        //封装查询条件
        QueryWrapper<ManufactureApply> queryWrapper = new QueryWrapper<>();
        //查询条件的判断
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getSearch_firstKindId())){
                queryWrapper.eq("first_kind_id",vo.getSearch_firstKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_secondKindId())){
                queryWrapper.eq("second_kind_id",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_thirdKindId())){
                queryWrapper.eq("thirdKindId",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_type())){
                queryWrapper.eq("type",vo.getSearch_type());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime1())){
                queryWrapper.ge("register_time",vo.getSearch_registerTime1());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime2())){
                queryWrapper.le("register_time",vo.getSearch_registerTime2());
            }
        }
        // 额外添加2个条件
        // 审核状态：审核未通过
        queryWrapper.eq("check_tag","S001-0");
        // 派工标志：未派工
        queryWrapper.eq("manufacture_tag","P001-0");

        //使用分页工具
        PageHelper.startPage(pageNo,pageSize);
        List<ManufactureApply> manufactureApplyList =this.list(queryWrapper);
        PageInfo<ManufactureApply> manufactureApplyPageInfo = new PageInfo<>(manufactureApplyList);

        //将pageinfo 转换成 pageutils
        PageUtils<ManufactureApply> pageUtils = new PageUtils<>();
        pageUtils.setRows(manufactureApplyPageInfo.getList());
        pageUtils.setTotal(manufactureApplyPageInfo.getTotal());

        return pageUtils;
    }

    @Override
    public PageUtils<ManufactureApply> manufactureApplyListPage(DesignFileVo vo, int pageNo, int pageSize) {
        //封装查询条件
        QueryWrapper<ManufactureApply> queryWrapper = new QueryWrapper<>();
        // 额外添加1个条件
        // 审核状态：审核未通过
        queryWrapper.eq("check_tag","S001-1");

        //查询条件的判断
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getSearch_firstKindId())){
                queryWrapper.eq("first_kind_id",vo.getSearch_firstKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_secondKindId())){
                queryWrapper.eq("second_kind_id",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_thirdKindId())){
                queryWrapper.eq("thirdKindId",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime1())){
                queryWrapper.ge("register_time",vo.getSearch_registerTime1());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime2())){
                queryWrapper.le("register_time",vo.getSearch_registerTime2());
            }
        }
        //使用分页工具
        PageHelper.startPage(pageNo,pageSize);
        List<ManufactureApply> manufactureApplyList =this.list(queryWrapper);
        PageInfo<ManufactureApply> manufactureApplyPageInfo = new PageInfo<>(manufactureApplyList);

        //将pageinfo 转换成 pageutils
        PageUtils<ManufactureApply> pageUtils = new PageUtils<>();
        pageUtils.setRows(manufactureApplyPageInfo.getList());
        pageUtils.setTotal(manufactureApplyPageInfo.getTotal());

        return pageUtils;
    }

    @Override
    public PageUtils<ManufactureApply> manufactureApplyListPage2(DesignFileVo vo, int pageNo, int pageSize) {
        //封装查询条件
        QueryWrapper<ManufactureApply> queryWrapper = new QueryWrapper<>();
        // 额外添加1个条件
        // 审核状态：审核未通过
        queryWrapper.eq("check_Tag","S001-1");

        // 派工标志 未派工
        queryWrapper.eq("manufacture_Tag","P001-0");
        //查询条件的判断
        if(vo!=null){
            if(!StringUtils.isEmpty(vo.getSearch_firstKindId())){
                queryWrapper.eq("first_kind_id",vo.getSearch_firstKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_secondKindId())){
                queryWrapper.eq("second_kind_id",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_thirdKindId())){
                queryWrapper.eq("thirdKindId",vo.getSearch_secondKindId());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime1())){
                queryWrapper.ge("register_time",vo.getSearch_registerTime1());
            }
            if(!StringUtils.isEmpty(vo.getSearch_registerTime2())){
                queryWrapper.le("register_time",vo.getSearch_registerTime2());
            }
        }
        //使用分页工具
        PageHelper.startPage(pageNo,pageSize);
        List<ManufactureApply> manufactureApplyList =this.list(queryWrapper);
        PageInfo<ManufactureApply> manufactureApplyPageInfo = new PageInfo<>(manufactureApplyList);

        //将pageinfo 转换成 pageutils
        PageUtils<ManufactureApply> pageUtils = new PageUtils<>();
        pageUtils.setRows(manufactureApplyPageInfo.getList());
        pageUtils.setTotal(manufactureApplyPageInfo.getTotal());

        return pageUtils;
    }
}
